package com.lovo.ssc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.ssc.bean.SysUser;
import com.lovo.ssc.mapper.SysUserMapper;
import com.lovo.ssc.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public SysUser login(String userName, String pwd) {
        QueryWrapper<SysUser> qw=new QueryWrapper<>();
        qw.eq("userName",userName);
        qw.eq("userPwd",pwd);
        return baseMapper.selectOne(qw);
    }

    @Override
    public SysUser findByUserName(String userName) {
        QueryWrapper<SysUser> qw=new QueryWrapper<>();
        qw.eq("userName",userName);
        return baseMapper.selectOne(qw);
    }

    @Override
    public String setAuditStatus(String userName, Integer code, String reason, String level) {

        QueryWrapper<SysUser> qw=new QueryWrapper<>();
        qw.eq("userName",userName);
        SysUser user =baseMapper.selectOne(qw);

        if (code ==1){
            user.setAuditStatus(1);
            user.setUserLevel(level);
        }else {
            user.setAuditStatus(2);
            user.setAuditReason(reason);
        }

        baseMapper.update(user,qw);
        return "ok";
    }

    @Override
    public String setFreeze(String userName, Integer code) {
        QueryWrapper<SysUser> qw=new QueryWrapper<>();
        qw.eq("userName",userName);
        SysUser user=baseMapper.selectOne(qw);
        user.setUserFreeze(code);
        baseMapper.update(user,qw);
        return "ok";

    }
}

